package com.axt.dbaudit.action.query;

import java.util.*;
import com.axt.dbaudit.base.QueryFilter;
import com.axt.soa.action.*;
import org.apache.struts2.json.annotations.JSON;
import com.google.gson.Gson;
import com.google.gson.reflect.*;

public class QueryBaseAction extends BaseAction {
	protected List<QueryFilter> filters = null;
	protected int queryInResult = 0;
	protected int maxRowNum = 0;
	protected int statDim = 0;
	protected int sort = 0;
	protected int totalRows = 0;
	protected String queryProgress = "";
	protected String queryDate = "";
	
	public List<QueryFilter> getFilters() {
		return filters;
	}
	public void setFilters(List<QueryFilter> filters) {
		this.filters = filters;
	}
	
	public void setFilters(String filterString) {
		Gson gson = new Gson();
		try {
			this.filters = gson.fromJson(filterString, new TypeToken<ArrayList<QueryFilter>>(){}.getType());
		} catch (Exception e) {
			/* ignore */
			this.filters = null;
		}
	}
	
	public int getQueryInResult() {
		return queryInResult;
	}
	public void setQueryInResult(int queryInResult) {
		this.queryInResult = queryInResult;
	}
	public int getMaxRowNum() {
		return maxRowNum;
	}
	public void setMaxRowNum(int maxRowNum) {
		this.maxRowNum = maxRowNum;
	}
	public int getStatDim() {
		return statDim;
	}
	public void setStatDim(int statDim) {
		this.statDim = statDim;
	}
	public int getSort() {
		return sort;
	}
	public void setSort(int sort) {
		this.sort = sort;
	}
	
	@JSON(name="totalRows")
	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	
	@JSON(name="queryProgress")
	public String getQueryProgress() {
		return queryProgress;
	}
	public void setQueryProgress(String queryProgress) {
		this.queryProgress = queryProgress;
	}
	
	@JSON(name="queryDate")
	public String getQueryDate() {
		return queryDate;
	}
	public void setQueryDate(String queryDate) {
		this.queryDate = queryDate;
	}
	
	public static void main(String[] args) throws Exception{
		String str = "[";
		str += "{\"filterType\":1,\"filterRelation\":2,\"filterLogic\":3, \"filterValue\":\"ab##cd\"}";
		str += ",";
		str += "{\"filterType\":4,\"filterRelation\":5,\"filterLogic\":6, \"filterValue\":\"ab##cd$$ef##hj\"}";
		str += "]";
		
		new QueryBaseAction().setFilters(str);
	}
	
}
